/**
 *
 * \file DirParser_Win32.cpp
 *	\brief DirParser declaration class
 * \author Edouard ROGE
 * \date 27 february 2011
 *
 */

#include "DirParser.h"

namespace Core
{
	namespace File
	{
		DirParser::DirParser()
		{
			m_hSearch = INVALID_HANDLE_VALUE;
		}

		DirParser::~DirParser()
		{
		}

		bool DirParser::Open(const std::string & _strURI, const std::string & _strExt)
		{
			m_URI = _strURI + "*." + _strExt;
			m_hSearch = FindFirstFile(m_URI.GetURI().c_str(), &m_File);
			return (m_hSearch != INVALID_HANDLE_VALUE);
		}

		bool DirParser::Close()
		{
			return FindClose(m_hSearch) == TRUE;
		}

		bool DirParser::Iterate(std::string & _strFileName)
		{
			if (m_hSearch != INVALID_HANDLE_VALUE)
			{
				_strFileName = std::string(m_File.cFileName);
				if (!FindNextFile(m_hSearch, &m_File))
					m_hSearch = INVALID_HANDLE_VALUE;
				return true;
			}
			return false;
		}
	}
}